package com.tskj.leonsu.dao;

import com.alibaba.fastjson.JSONObject;
import com.tskj.leonsu.db.DbUtilitys_gygl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author LeonSu
 */
@Component
public class GyglDAO {

    @Autowired
    private DbUtilitys_gygl dbUtilitys_gygl;

    public JSONObject getStudentInfo(String name, String no, String idCard) {
        String sql = "select FIELDB8BA2237D21A464D,FIELD616F0E769F894E35,FIELD0AE256A32CCF4320 from DOCUMENT4DFC4B4BECEC4C82 where FIELD29CE51A665F34BDA=?";// and FIELD29CE51A665F34BDA=?";
        List<Map<String, Object>> list = null;
        if (idCard.isEmpty()) {
            list = dbUtilitys_gygl.execSQL(sql, no);
        } else {
            sql += " OR FIELD29CE51A665F34BDA=?";
            list = dbUtilitys_gygl.execSQL(sql, no, idCard);
        }
        JSONObject json = new JSONObject();
        if (list == null || list.size() == 0) {
            return json;
        } else {
            Object obj = list.get(0).get("FIELDB8BA2237D21A464D");
            if (obj == null || obj.toString().isEmpty()) {
                json.put("sex", "");
            } else {
                json.put("sex", obj.toString().trim());
            }
            obj = list.get(0).get("FIELD616F0E769F894E35");
            if (obj == null || obj.toString().isEmpty()) {
                json.put("xueyuan", "");
            } else {
                json.put("xueyuan", obj.toString().trim());
            }
            obj = list.get(0).get("FIELD0AE256A32CCF4320");
            if (obj == null || obj.toString().isEmpty()) {
                json.put("studentname", "");
            } else {
                json.put("studentname", obj.toString().trim());
            }
            return json;
        }
    }

    public String getStudentSex(String name, String no) {
        String sql = "select FIELDB8BA2237D21A464D from DOCUMENT4DFC4B4BECEC4C82 where FIELD0AE256A32CCF4320=?";// and FIELD29CE51A665F34BDA=?";
        List<Map<String, Object>> list = dbUtilitys_gygl.execSQL(sql, name);
        if (list == null || list.size() == 0) {
            return "";
        } else {
            Object obj = list.get(0).get("FIELDB8BA2237D21A464D");
            if (obj == null || obj.toString().isEmpty()) {
                return "";
            } else {
                return obj.toString().trim();
            }
        }
    }

    public String getStudentXueYuan(String name, String no) {
//        System.out.println(name + " , " + no + "!!!!");
        String sql = "select FIELD616F0E769F894E35 from DOCUMENT4DFC4B4BECEC4C82 where FIELD0AE256A32CCF4320=?";// and FIELD29CE51A665F34BDA=?";
        List<Map<String, Object>> list = dbUtilitys_gygl.execSQL(sql, name);
        if (list == null || list.size() == 0) {
            return "";
        } else {
            Object obj = list.get(0).get("FIELDB8BA2237D21A464D");
            if (obj == null || obj.toString().isEmpty()) {
                return "";
            } else {
                return obj.toString().trim();
            }
        }
    }
}
